/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ihmprojet;

import edu.uci.ics.jung.algorithms.layout.*;
import edu.uci.ics.jung.graph.*;
import edu.uci.ics.jung.visualization.*;
import edu.uci.ics.jung.visualization.control.*;
import edu.uci.ics.jung.visualization.decorators.*;
import edu.uci.ics.jung.visualization.renderers.BasicVertexLabelRenderer;
import ihmprojet.core.model.Arrete;
import ihmprojet.core.model.DelegateTreeOperators;
import ihmprojet.core.model.Sommet;
import ihmprojet.view.renderer.TreeOperatorRenderer;
import ihmprojet.core.model.operateur.OperateurBinaire;
import ihmprojet.view.transformer.IconLoader;
import ihmprojet.view.transformer.SommetIconTransformer;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import javax.swing.Icon;
import javax.swing.JFrame;
import org.apache.commons.collections15.Transformer;

/**
 *
 * @author nell
 */
public class TestJung extends javax.swing.JFrame {

    /**
     * Creates new form TestJung
     */
    public TestJung() {
        initComponents();
        setLayout(new FlowLayout());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TestJung.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TestJung.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TestJung.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TestJung.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                TestJung tj = new TestJung();
                IconLoader il = new IconLoader();
                il.load(new File("images/tasks"), "gif");
                //tj.setVisible(true);

                DelegateTreeOperators<Sommet, Arrete> g = new DelegateTreeOperators<>();
                Sommet v1 = new Sommet("1");
                Sommet v2 = new Sommet("2");
                Sommet v3 = new Sommet("3");
                Sommet v4 = new Sommet("4");
                Sommet v5 = new Sommet("5");
                g.addVertex(v1);
                g.addEdge(new Arrete("1->"), v1, v2);
                g.addEdge(new Arrete("2->"), v1, v3);
                g.addEdge(new Arrete("3->"), v1, v4);
                g.addEdge(new Arrete("4->"), v1, v5);
//                g.addEdge("ytest->", v4, v5);

                g.addOperateur(v2, v3, "&");
                System.out.println(g);
                //We create our graph in here
                // The Layout<V, E> is parameterized by the vertex and edge types
                // SimpleGraphView sgv = new SimpleGraphView(); //We create our graph in here
                // The Layout<V, E> is parameterized by the vertex and edge types
                TreeLayout<Sommet, Arrete> layout = new TreeLayout<>(g);
                //layout.setSize(new Dimension(300, 300)); // sets the initial size of the layout space
                // The BasicVisualizationServer<V,E> is parameterized by the vertex and edge types
                VisualizationViewer<Sommet, Arrete> vv = new VisualizationViewer<>(layout);
                vv.setRenderer(new TreeOperatorRenderer<Sommet, Arrete>());
                DefaultModalGraphMouse dmgm = new DefaultModalGraphMouse();
                dmgm.setMode(ModalGraphMouse.Mode.PICKING);
                vv.setGraphMouse(dmgm);
                vv.getRenderContext().setVertexIconTransformer(new SommetIconTransformer(il));
                vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Sommet>());

                //vv.setPreferredSize(new Dimension(350, 350)); //Sets the viewing area size

                //vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
                //vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());



                JFrame frame = tj;
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.getContentPane().add(new GraphZoomScrollPane(vv));
                frame.pack();
                frame.setVisible(true);

            }
        });
    }
//
//    @Override
//    protected void paintComponent(Graphics g) {
//        super.paintComponent(g);
//
//        Graphics2D g2d = (Graphics2D) g;
//        if (doubleBuffered) {
//            checkOffscreenImage(getSize());
//            renderGraph(offscreenG2d);
//            g2d.drawImage(offscreen, null, 0, 0);
//        } else {
//            renderGraph(g2d);
//        }
//    }
//
//    protected void renderGraph(Graphics2D g2d) {
//        if (renderContext.getGraphicsContext() == null) {
//            renderContext.setGraphicsContext(new GraphicsDecorator(g2d));
//        } else {
//            renderContext.getGraphicsContext().setDelegate(g2d);
//        }
//        renderContext.setScreenDevice(this);
//        Layout<V, E> layout = model.getGraphLayout();
//
//        g2d.setRenderingHints(renderingHints);
//
//        // the size of the VisualizationViewer
//        Dimension d = getSize();
//
//        // clear the offscreen image
//        g2d.setColor(getBackground());
//        g2d.fillRect(0, 0, d.width, d.height);
//
//        AffineTransform oldXform = g2d.getTransform();
//        AffineTransform newXform = new AffineTransform(oldXform);
//        newXform.concatenate(
//                renderContext.getMultiLayerTransformer().getTransformer(Layer.VIEW).getTransform());
////        		viewTransformer.getTransform());
//
//        g2d.setTransform(newXform);
//
//        // if there are  preRenderers set, paint them
//        for (Paintable paintable : preRenderers) {
//
//            if (paintable.useTransform()) {
//                paintable.paint(g2d);
//            } else {
//                g2d.setTransform(oldXform);
//                paintable.paint(g2d);
//                g2d.setTransform(newXform);
//            }
//        }
//
//        if (layout instanceof Caching) {
//            ((Caching) layout).clear();
//        }
//
//        renderer.render(renderContext, layout);
//
//        // if there are postRenderers set, do it
//        for (Paintable paintable : postRenderers) {
//
//            if (paintable.useTransform()) {
//                paintable.paint(g2d);
//            } else {
//                g2d.setTransform(oldXform);
//                paintable.paint(g2d);
//                g2d.setTransform(newXform);
//            }
//        }
//        g2d.setTransform(oldXform);
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
